package com.wzh.houseEs.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.wzh.common.utils.PageUtils;
import com.wzh.common.utils.R;
import com.wzh.houseEs.feign.HouseFeign;
import com.wzh.houseEs.feign.UserFeign;
import com.wzh.houseEs.service.EsService;
import com.wzh.houseEs.vo.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.lucene.search.TotalHits;
import org.apache.lucene.search.join.ScoreMode;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.text.Text;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.NestedQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.Aggregations;
import org.elasticsearch.search.aggregations.bucket.nested.Nested;
import org.elasticsearch.search.aggregations.bucket.nested.NestedAggregationBuilder;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * @author WZH
 * @title: EsServiceImpl
 * @projectName find_house
 * @description:
 * @date 2022/3/22
 */
@Service
public class EsServiceImpl implements EsService {

    @Autowired
    private RestHighLevelClient client;
    @Autowired
    private HouseFeign houseFeign;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private UserFeign userFeign;

    @Override
    public SearchResultVo newHouseList(SearchParam searchParam) {
        //朝向判断
        List<String> attrParam2=null;
        if (searchParam.getAttrs()!=null&&searchParam.getAttrs().size()>0){
            attrParam2= searchParam.getAttrs().stream().filter(item -> !item.contains("朝向")).collect(Collectors.toList());
            List<String> attrParam1 = searchParam.getAttrs().stream().filter(item -> item.contains("朝向")).collect(Collectors.toList());
            if (attrParam1.size()>1){
                String aspect= "朝向_";
                for (String item : attrParam1) {
                    if (!aspect.contains(item.split("_")[1])){
                        String[] s = item.split("_");
                        aspect += s[1] + ":";
                    }
                }
                aspect=aspect.substring(0,aspect.length()-1);
                attrParam2.add(aspect);
            }else if (attrParam1.size()==1){
                attrParam2.add(attrParam1.get(0));
            }
        }
        // es查询
        SearchRequest searchRequest = new SearchRequest("newhouse");
        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        //构建条件
        BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
        //新房/二手房
        if (searchParam.getFlag()!=null){
            boolQueryBuilder.must(QueryBuilders.matchQuery("flag",searchParam.getFlag()));
        }
        //查询房屋名
        if (StringUtils.isNotBlank(searchParam.getKeyword())){
            boolQueryBuilder.must(QueryBuilders.matchQuery("houseName",searchParam.getKeyword()));
        }
        //查询面积
        if (searchParam.getHouseArea()!=null){
            boolQueryBuilder.must(QueryBuilders.termQuery("houseArea",searchParam.getHouseArea()));
        }
        //价格区间查询
        if (StringUtils.isNotBlank(searchParam.getHousePrice())&&!searchParam.getHousePrice().substring(searchParam.getHousePrice().length()-1).equals("_")){
            String[] split = searchParam.getHousePrice().split(",");
            // 区间：100_200 大于：200_ 小于：_200
            String[] price = split[split.length-1].split("_");
            if (searchParam.getHousePrice().startsWith("_")){
                boolQueryBuilder.must(QueryBuilders.rangeQuery("housePrice").lte(price[1]));
            }else if (searchParam.getHousePrice().endsWith("_")){
                boolQueryBuilder.must(QueryBuilders.rangeQuery("housePrice").gte(price[0]));
            }else {
                boolQueryBuilder.must(QueryBuilders.rangeQuery("housePrice").lte(price[1]).gte(price[0]));
            }
        }
        //属性查询
        if (attrParam2!=null&&attrParam2.size()>0) {
            attrParam2.stream().forEach(item->{
                //多个非扁平化处理的bool查询
                //attrs=朝向_东:西
                String[] attr = item.split("_");
                BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
                boolQuery.must(QueryBuilders.termQuery("attrs.attrName",attr[0]));
                String[] attrValue = attr[1].split(":");
                boolQuery.must(QueryBuilders.termsQuery("attrs.attrValue",attrValue));
                NestedQueryBuilder attrItem = QueryBuilders.nestedQuery("attrs", boolQuery, ScoreMode.None);
                boolQueryBuilder.must(attrItem);
            });
        }
        searchSourceBuilder.query(boolQueryBuilder);
        //聚合构建
        NestedAggregationBuilder attrsAgg = AggregationBuilders.nested("attrAgg","attrs");
        TermsAggregationBuilder attrsNameAgg = AggregationBuilders.terms("attrsNameAgg").field("attrs.attrName");
        attrsNameAgg.subAggregation(AggregationBuilders.terms("attrsValueAgg").field("attrs.attrValue"));
        attrsAgg.subAggregation(attrsNameAgg);
        searchSourceBuilder.aggregation(attrsAgg);
        //高亮
        HighlightBuilder highlightBuilder = new HighlightBuilder()
                .field("houseName")
                .preTags("<span style='color:red'>")
                .postTags("</span>");
        searchSourceBuilder.highlighter(highlightBuilder);
        //分页
        searchSourceBuilder.from((searchParam.getPageNum()-1)*searchParam.getSize());
        searchSourceBuilder.size(searchParam.getSize());
        searchRequest.source(searchSourceBuilder);
        SearchResponse searchResponse=null;
        //同步执行
        try {
            searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
        } catch (IOException e) {
            e.printStackTrace();
        }
        //处理结果
        SearchHits hits = searchResponse.getHits();
        TotalHits totalHits = hits.getTotalHits();
// the total number of hits, must be interpreted in the context of totalHits.relation
        long numHits = totalHits.value;
// whether the number of hits is accurate (EQUAL_TO) or a lower bound of the total (GREATER_THAN_OR_EQUAL_TO)
        TotalHits.Relation relation = totalHits.relation;
        float maxScore = hits.getMaxScore();
        SearchHit[] searchHits = hits.getHits();
        //添加房屋信息
        List<NewHouseVo> newHouseVos = new ArrayList<>();
        for (SearchHit hit : searchHits) {
            // do something with the SearchHit
            String index = hit.getIndex();
            String id = hit.getId();
            float score = hit.getScore();
            String sourceAsString = hit.getSourceAsString();
            NewHouseVo newHouseVo = JSON.parseObject(sourceAsString, NewHouseVo.class);
            Map<String, HighlightField> highlightFields = hit.getHighlightFields();
            HighlightField highlight = highlightFields.get("houseName");
            if (highlight!=null){
                Text[] fragments = highlight.fragments();
                String fragmentString = fragments[0].string();
                newHouseVo.setHouseName(fragmentString);
            }
            newHouseVos.add(newHouseVo);
        }
        //处理聚合
        Aggregations aggregations = searchResponse.getAggregations();
        Nested attrAggRes = aggregations.get("attrAgg");
        Aggregations attrNested = attrAggRes.getAggregations();
        Terms attrsNameAggRes = attrNested.get("attrsNameAgg");
        List<SearchResultVo.AttrValues> AttrValues = attrsNameAggRes.getBuckets().stream().map(item -> {
            SearchResultVo.AttrValues attrValues = new SearchResultVo.AttrValues();
            attrValues.setAttrName(item.getKeyAsString());
            Aggregations itemRes = item.getAggregations();
            Terms attrsValueAgg = itemRes.get("attrsValueAgg");
            List<String> attrValue = attrsValueAgg.getBuckets().stream().map(item2 -> {
                return item2.getKeyAsString();
            }).collect(Collectors.toList());
            attrValues.setAttrValue(attrValue);
            return attrValues;
        }).collect(Collectors.toList());
        //封装VO
        SearchResultVo resultVo = new SearchResultVo();
        resultVo.setNewHouses(newHouseVos);
        resultVo.setPageNum(searchParam.getPageNum());
        resultVo.setPageSize(searchParam.getSize());
        resultVo.setTotal(numHits);
        resultVo.setAttrValues(AttrValues);
        return resultVo;
    }

    @Override
    public R upNewHouse(NewHouseVo newHouseVo) {
        IndexRequest request = new IndexRequest("newhouse");
        request.id(newHouseVo.getHouseId().toString());
        String jsonString = JSON.toJSONString(newHouseVo);
        request.source(jsonString, XContentType.JSON);
        try {
            IndexResponse indexResponse = client.index(request, RequestOptions.DEFAULT);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return R.ok();
    }

    @Override
    public EsVo searchlist(Map<String, Object> params) {
        String searchparam = (String) params.get("searchparam");
        String price = (String) params.get("price");
        String type = (String) params.get("type");
        String cz = (String) params.get("cz");
        String status = (String) params.get("status");
        String page = (String) params.get("page");
        String size = (String) params.get("size");
        SearchRequest searchRequest = new SearchRequest("renhouse");
        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
        if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotEmpty(searchparam)&&!"null".equals(searchparam)) {
            boolQueryBuilder.must(QueryBuilders.matchQuery("houseName",searchparam));
        }  if ( com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotEmpty(price) ){
            boolQueryBuilder.must(QueryBuilders.termQuery("housePrice",Double.valueOf(price)));
        } if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotEmpty(type) ){
            boolQueryBuilder.must(QueryBuilders.termQuery("houseDesc.keyword",type));
        } if ( com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotEmpty(status)){
            boolQueryBuilder.must(QueryBuilders.termQuery("status",status));
        }  if ( com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotEmpty(cz)){
            boolQueryBuilder.must(QueryBuilders.termQuery("houseWay",cz));
        }
        searchSourceBuilder.query(boolQueryBuilder);
//        if (!searchparam.equals("")) {
//            boolQueryBuilder.must(QueryBuilders.matchQuery("houseAddress", searchparam));
//        }
        TermsAggregationBuilder field = AggregationBuilders.terms("houseDescAgg").field("houseDesc.keyword");
        TermsAggregationBuilder field1 = AggregationBuilders.terms("hourpriceAgg").field("housePrice");
        TermsAggregationBuilder field3 = AggregationBuilders.terms("statusAgg").field("status");
        TermsAggregationBuilder field2 = AggregationBuilders.terms("houseWayAgg").field("houseWay");

        searchSourceBuilder.aggregation(field);
        searchSourceBuilder.aggregation(field2);
        searchSourceBuilder.aggregation(field1);
        searchSourceBuilder.aggregation(field3);
        searchSourceBuilder.size(Integer.parseInt(size));
        searchSourceBuilder.from((Integer.parseInt(page)-1)*Integer.parseInt(size));
        HighlightBuilder highlightBuilder = new HighlightBuilder();
        HighlightBuilder.Field highlightUser = new HighlightBuilder.Field("houseName");
        highlightBuilder.field(highlightUser);
        highlightBuilder.postTags("</span>");
        highlightBuilder.preTags("<span style=\"color: red;\">");
        searchSourceBuilder.highlighter(highlightBuilder);
        searchSourceBuilder.sort("rentSort",SortOrder.DESC).sort("createTime",SortOrder.ASC);
        searchRequest.source(searchSourceBuilder);
        SearchResponse searchResponse = null;
        try {
            searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
        } catch (IOException e) {
            e.printStackTrace();
        }
        SearchHits hits = searchResponse.getHits();
        TotalHits totalHits = hits.getTotalHits();
// the total number of hits, must be interpreted in the context of totalHits.relation
        long numHits = totalHits.value;
// whether the number of hits is accurate (EQUAL_TO) or a lower bound of the total (GREATER_THAN_OR_EQUAL_TO)
        TotalHits.Relation relation = totalHits.relation;
        float maxScore = hits.getMaxScore();
        SearchHit[] searchHits = hits.getHits();
        ArrayList<NewHouseVo> newHouseEntities = new ArrayList<>();
        for (SearchHit hit : searchHits) {
            // do something with the SearchHit
            String sourceAsString = hit.getSourceAsString();
            NewHouseVo newHouseVo = JSONObject.parseObject(sourceAsString, NewHouseVo.class);
            Map<String, HighlightField> highlightFields = hit.getHighlightFields();

            HighlightField highlight = highlightFields.get("houseName");

            if (highlight != null) {
                Text[] fragments = highlight.fragments();
                String fragmentString = fragments[0].string();
                newHouseVo.setHouseName(fragmentString);
                newHouseVo.setHouseAddress(fragmentString);
            }
            newHouseEntities.add(newHouseVo);
        }

        HouseDescVo houseDescVo = getData(searchResponse);
        EsVo esVo = new EsVo();
        esVo.setPageUtils(new PageUtils(newHouseEntities, Integer.parseInt(numHits + ""), Integer.parseInt(size), Integer.parseInt(page)));
        esVo.setHouseDescVo(houseDescVo);
        return esVo;
    }
    @Override
    public EsVo searchlist2(Map<String, Object> params,Integer user_id) throws IOException {

        List<RentHouseVo> rentHouseVos = houseFeign.MyRentHouseList(user_id);

        if (rentHouseVos!=null&&rentHouseVos.size()>0) {
            BulkRequest bulkRequest = new BulkRequest();
            for (RentHouseVo rentHouseVo : rentHouseVos) {
                IndexRequest request = new IndexRequest("renhouse");
                request.id(rentHouseVo.getHouseId() + "");
                String jsonString = JSON.toJSONString(rentHouseVo);
                request.source(jsonString, XContentType.JSON);
                bulkRequest.add(request);
            }
            BulkResponse bulkResponse = client.bulk(bulkRequest, RequestOptions.DEFAULT);
        }

        String searchparam = (String) params.get("searchparam");
        String price = (String) params.get("price");
        String type = (String) params.get("type");
        String cz = (String) params.get("cz");
        String status = (String) params.get("status");
        String page = (String) params.get("page");
        String size = (String) params.get("size");
        SearchRequest searchRequest = new SearchRequest("renhouse");
        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
        if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotEmpty(searchparam)&&!"null".equals(searchparam)) {
            boolQueryBuilder.must(QueryBuilders.matchQuery("houseName",searchparam));
        }  if ( com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotEmpty(price) ){
            boolQueryBuilder.must(QueryBuilders.termQuery("housePrice",Double.valueOf(price)));
        } if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotEmpty(type) ){
            boolQueryBuilder.must(QueryBuilders.termQuery("houseDesc.keyword",type));
        } if ( com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotEmpty(status)){
            boolQueryBuilder.must(QueryBuilders.termQuery("status",status));
        }  if ( com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotEmpty(cz)){
            boolQueryBuilder.must(QueryBuilders.termQuery("houseWay",cz));
        }

        boolQueryBuilder.must(QueryBuilders.termQuery("userId",user_id));
        searchSourceBuilder.query(boolQueryBuilder);
//        if (!searchparam.equals("")) {
//            boolQueryBuilder.must(QueryBuilders.matchQuery("houseAddress", searchparam));
//        }
        TermsAggregationBuilder field = AggregationBuilders.terms("houseDescAgg").field("houseDesc.keyword");
        TermsAggregationBuilder field1 = AggregationBuilders.terms("hourpriceAgg").field("housePrice");
        TermsAggregationBuilder field3 = AggregationBuilders.terms("statusAgg").field("status");
        TermsAggregationBuilder field2 = AggregationBuilders.terms("houseWayAgg").field("houseWay");

        searchSourceBuilder.aggregation(field);
        searchSourceBuilder.aggregation(field2);
        searchSourceBuilder.aggregation(field1);
        searchSourceBuilder.aggregation(field3);
        searchSourceBuilder.size(Integer.parseInt(size));
        searchSourceBuilder.from((Integer.parseInt(page)-1)*Integer.parseInt(size));
        HighlightBuilder highlightBuilder = new HighlightBuilder();
        HighlightBuilder.Field highlightUser = new HighlightBuilder.Field("houseName");
        highlightBuilder.field(highlightUser);
        highlightBuilder.postTags("</span>");
        highlightBuilder.preTags("<span style=\"color: red;\">");
        searchSourceBuilder.highlighter(highlightBuilder);
        searchRequest.source(searchSourceBuilder);
        SearchResponse searchResponse = null;
        try {
            searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
        } catch (IOException e) {
            e.printStackTrace();
        }
        SearchHits hits = searchResponse.getHits();
        TotalHits totalHits = hits.getTotalHits();
// the total number of hits, must be interpreted in the context of totalHits.relation
        long numHits = totalHits.value;
// whether the number of hits is accurate (EQUAL_TO) or a lower bound of the total (GREATER_THAN_OR_EQUAL_TO)
        TotalHits.Relation relation = totalHits.relation;
        float maxScore = hits.getMaxScore();
        SearchHit[] searchHits = hits.getHits();
        ArrayList<NewHouseVo> newHouseEntities = new ArrayList<>();
        for (SearchHit hit : searchHits) {
            // do something with the SearchHit
            String sourceAsString = hit.getSourceAsString();
            NewHouseVo newHouseVo = JSONObject.parseObject(sourceAsString, NewHouseVo.class);
            Map<String, HighlightField> highlightFields = hit.getHighlightFields();

            HighlightField highlight = highlightFields.get("houseName");

            newHouseVo.setUserId(user_id);
            if (highlight != null) {
                Text[] fragments = highlight.fragments();
                String fragmentString = fragments[0].string();
                newHouseVo.setHouseName(fragmentString);
                newHouseVo.setHouseAddress(fragmentString);
            }
            newHouseEntities.add(newHouseVo);
        }

        HouseDescVo houseDescVo = getData(searchResponse);
        EsVo esVo = new EsVo();
        esVo.setPageUtils(new PageUtils(newHouseEntities, Integer.parseInt(numHits + ""), Integer.parseInt(size), Integer.parseInt(page)));
        esVo.setHouseDescVo(houseDescVo);
        return esVo;
    }

    //置顶操作
    @Override
    @Transactional
    public R getById1(Integer houseId) throws IOException {

        R info1 = houseFeign.info(houseId);
        //先获取房子信息
        RentHouseVo rentHouseEntity = info1.getData(new TypeReference<RentHouseVo>(){});
        //根据user找到用户
        R info = userFeign.info(Long.valueOf(rentHouseEntity.getUserId()));
        UserVo userVo = info.getData(new TypeReference<UserVo>(){});
        //判断余额
        BigDecimal b = new BigDecimal (1200);
        //如果余额小于1200
        if (userVo.getMoney().doubleValue()<1200.00){

            return R.error("余额不足，请先充值");
        }
        //大于1200就扣钱
        userVo.setMoney(userVo.getMoney().subtract(b));
        userFeign.update(userVo);
        if (rentHouseEntity.getRentSort()>0){
            return R.error("置顶未过期，请勿重复置顶");
        }
        //设置花钱置顶的rent_sort 标记为3
        rentHouseEntity.setRentSort(3);
        //时间默认一个月 30天
        rentHouseEntity.setDeadline(1);
        //修改house
        houseFeign.updateZd(rentHouseEntity);

        String s = (String) redisTemplate.opsForValue().get(houseId+"");
        if (org.apache.commons.lang.StringUtils.isNotEmpty(s)){
            //如果redis获取的值不为空，就给他重置置顶时间一个月
            redisTemplate.expire(houseId+"", 30, TimeUnit.DAYS);

        }else {
            redisTemplate.opsForValue().set(houseId+"",houseId+"",30, TimeUnit.DAYS);

        }

        List<RentHouseVo> rentHouseVos = houseFeign.MyRentHouseList2();
        System.out.println(rentHouseVos);
        if (rentHouseVos!=null&&rentHouseVos.size()>0) {
            BulkRequest bulkRequest = new BulkRequest();
            for (RentHouseVo rentHouseVo : rentHouseVos) {
                IndexRequest request = new IndexRequest("renhouse");
                request.id(rentHouseVo.getHouseId() + "");
                String jsonString = JSON.toJSONString(rentHouseVo);
                request.source(jsonString, XContentType.JSON);
                bulkRequest.add(request);
            }
            BulkResponse bulkResponse = client.bulk(bulkRequest, RequestOptions.DEFAULT);
        }

        return R.ok();
    }

    public HouseDescVo getData(SearchResponse searchResponse){

        Aggregations aggregations = searchResponse.getAggregations();
        Terms houseDescAgg = aggregations.get("houseDescAgg");
        HouseDescVo houseDescVo = new HouseDescVo();
        ArrayList<String> strings = new ArrayList<>();
        for (Terms.Bucket bucket : houseDescAgg.getBuckets()) {
            strings.add(bucket.getKeyAsString());
        }
        houseDescVo.setDesc(strings);
        houseDescVo.setType("户型");

        Terms hourpriceAgg = aggregations.get("hourpriceAgg");

        List<String> hourpriceList = new ArrayList<>();
        for (Terms.Bucket bucket : hourpriceAgg.getBuckets()) {
            hourpriceList.add(bucket.getKeyAsString());
        }
        houseDescVo.setPrice("房源价格");
        houseDescVo.setPricelist(hourpriceList);
        Terms statusAgg = aggregations.get("statusAgg");
        List<String> statusList = new ArrayList<>();

        for (Terms.Bucket bucket : statusAgg.getBuckets()) {
            String keyAsString = bucket.getKeyAsString();
            statusList.add(keyAsString);
        }
        houseDescVo.setStutus("是否出租");
        houseDescVo.setStutuslist(statusList);

        Terms houseWayAgg = aggregations.get("houseWayAgg");
        List<String> cxlist = new ArrayList<>();

        for (Terms.Bucket bucket : houseWayAgg.getBuckets()) {
            String keyAsString = bucket.getKeyAsString();
            cxlist.add(keyAsString);
        }
        houseDescVo.setCx("租房方式");
        houseDescVo.setCxlist(cxlist);

        return houseDescVo;
    }

    //每天凌晨1点执行一次
    @Scheduled(cron = "0 0 1 * * *")
    public void look(){
        List<RentHouseVo> list = houseFeign.selectBySort();
        //查询全部sort为3 的房子
        for (RentHouseVo rentHouseEntity : list) {
            //循环判断redis过期没
            String o = (String) redisTemplate.opsForValue().get(rentHouseEntity.getHouseId() + "");
            if (StringUtils.isNotEmpty(o)){
                //过期就修改sort为0 和dealine为0
                rentHouseEntity.setRentSort(0);
                rentHouseEntity.setDeadline(0);
                houseFeign.updateZd(rentHouseEntity);
            }
        }

    }

}
